<template>
    <div class="app-container">
        <el-form inline>
            <el-form-item :label="patientInfo.patientName">
                <div class="patient_info">
                    <div class="info_item">{{ patientInfo.gender == 0 ? '女' : '男' }}</div>
                    <div class="info_item">{{ patientInfo.age }}岁</div>
                    <div class="info_item">{{ patientInfo.idCard }}</div>
                </div>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" size="small" @click="goBack">返回</el-button>
            </el-form-item>
        </el-form>
        <el-table :data="list">
            <el-table-column label="序号">
                <template slot-scope="scope">{{ scope.$index + 1 }}</template>
            </el-table-column>
            <el-table-column label="评估时间" prop="evaluateTime" />
            <el-table-column label="评估表名称" prop="name" />
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button type="text"
                        @click="jumpPage(scope.row.detailRoute, scope.row.relationId, 3)">详情</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
import { historyList } from '@/api/treatment/treatment.js'
import moment from 'moment'
const assessList = [
    {
        name: "针灸医疗记录单",
        editRoute: "acupunctureTemplate",
        detailRoute: "acupunctureTemplate",
        type: 13
    },
    {
        name: "康复治疗记录单",
        editRoute: "rehabRecordTemplate",
        detailRoute: "rehabRecordTemplate",
        type: 14
    },
    {
        name: "临床康复介入医疗记录单",
        editRoute: "clinicalRecordTemplate",
        detailRoute: "clinicalRecordTemplate",
        type: 15
    },
    {
        name: "滨江高压氧治疗的心理护理及安全告知书",
        editRoute: "hyperbaricNoticeBJTemplate",
        detailRoute: "hyperbaricNoticeBJTemplate",
        type: 16
    },
    {
        name: "高压氧治疗的心理护理及安全告知书",
        editRoute: "hyperbaricNoticeTemplate",
        detailRoute: "hyperbaricNoticeTemplate",
        type: 17
    },
    {
        name: "舱内治疗评估",
        editRoute: "chamberEvalTemplate",
        detailRoute: "chamberEvalTemplate",
        type: 18
    },
    // {
    //     name: '吞咽功能障碍评定',
    //     editRoute: 'SwallowEdit',
    //     detailRoute: 'SwallowView'
    // },
    // {
    //     name: '肺功能和日常生活评定表',
    //     editRoute: 'PulmonaryEdit',
    //     detailRoute: 'PulmonaryView'
    // },
    // {
    //     name: '周围性面神经炎治疗成绩评分表',
    //     editRoute: 'FacialNerveEdit',
    //     detailRoute: 'FacialNerveView'
    // },
    // {
    //     name: '初期康复评定记录表',
    //     editRoute: 'EarlyEdit',
    //     detailRoute: 'EarlyView'
    // },
    // {
    //     name: '中期康复评定记录表',
    //     editRoute: 'MidTermEdit',
    //     detailRoute: 'MidTermView'
    // },
    // {
    //     name: '出院前康复评定记录表',
    //     editRoute: 'DischargeEdit',
    //     detailRoute: 'DischargeView'
    // },
    // {
    //     name: '偏瘫运动功能评定表',
    //     editRoute: 'HemiplegiaEdit',
    //     detailRoute: 'HemiplegiaView'
    // },
    // {
    //     name: '神经损伤功能评定表',
    //     editRoute: 'NerveInjuryEdit',
    //     detailRoute: 'NerveInjuryView'
    // },
    // {
    //     name: '神经康复综合评定表',
    //     editRoute: 'NeurorehabilitationEdit',
    //     detailRoute: 'NeurorehabilitationView'
    // },
    // {
    //     name: '感知能力-耳聋分级',
    //     editRoute: 'DeafGradeEdit',
    //     detailRoute: 'DeafGradeView'
    // },
    // {
    //     name: '感知能力-程度评估',
    //     editRoute: 'DegreeEdit',
    //     detailRoute: 'DegreeView'
    // },
    // {
    //     name: '运动能力',
    //     editRoute: 'MotionEdit',
    //     detailRoute: 'MotionView'
    // },
]

export default {
    name: 'HistoryAssess',
    data() {
        return {
            id: 3,
            list: [],
            keyword: '',
            patientInfo: {
                patientName: ''
            }
        }
    },
    computed: {
        addRoutes() {
            if (this.$store.getters && this.$store.getters.addRouters) {
                return this.$store.getters.addRouters
            } else {
                return []
            }
        }
    },
    mounted() {
        this.id = this.$route.query.id
        this.getList()
    },
    methods: {
        getList() {
            historyList({
                reserveId: this.id
            }).then(res => {
                if (res.content && res.content.length) {
                    this.list = res.content.map(item => {
                        const assess = assessList.find(assess => assess.name === item.estimateName)
                        return {
                            ...assess,
                            evaluateTime: moment(item.evaluateTime).format('YYYY-MM-DD HH:mm:ss'),
                            relationId: item.relationId
                        }
                    })
                } else {
                    this.list = []
                }
                this.patientInfo = res.summary || {
                    patientName: ''
                }
            })
        },
        hasRoute(list, routeName) {
            return list.some(item => {
                if (item.name === routeName) {
                    return true
                } else {
                    if (item.children && item.children.length) {
                        return this.hasRoute(item.children, routeName)
                    } else {
                        return false
                    }
                }
            })
        },
        goBack() {
            history.back()
        },
        jumpPage(routeName, id, type) {
            this.$router.push({
                name: routeName,
                query: {
                    id,
                    type,
                    source: 3
                }
            })
        }
    }
}
</script>

<style lang="scss" scoped>
.patient_info {
    display: flex;
    align-items: center;

    .info_item {
        margin-right: 10px;
    }
}
</style>
